$(document).ready(function(){
	//showform_orderdetail();

    $('#menu .node').mouseover(function(){
        $(this).find('ul').css('visibility', 'visible');
    });

    $('#menu .node').mouseout(function(){
        $(this).find('ul').css('visibility', 'hidden');
    });
});
function showform_orderdetail(data){
	var height	=	$(document).height();
	var width	=	$(document).width();
	var width_layer	=	$('#order_detail_layer').width();
	$('#order_detail_layer').css({
		height: height,
		left: width / 2 - width_layer/2,
		display: 'block'	
	});
	$('#order_detail_layer_content').css('height', (height - $('#order_detail_layer h3').height()) - 50);
	//fill value
	$('#order_ordercode').html(data.Order.order_code);
	$('#buyer_name').val(data.Order.buyer_name);
	$('#buyer_phone').val(data.Order.buyer_phone);
	$('#buyer_address').val(data.Order.buyer_address);		
	$('#buyer_birthday').val(data.Order.buyer_birthday);
	$('#buyer_sex').val(data.Order.buyer_sex);	
	$('#buyer_email').val(data.Order.buyer_email);	
}
function closeform_orderdetail(){
	$('#order_detail_layer').fadeOut();
}

function showorderdetail(url_orderdetail){
	waiting_screen();
	var c = Math.floor(Math.random()*99999999999);
	$.ajax({
	  url: url_orderdetail + '/' + c,
	  dataType: 'json',
	  context: document.body,
	  success: function(data){
		if(data == '0'){
			alert('Không tìm thấy id này');
		}else{
			showform_orderdetail(data);
		}
	  }
	});
}

function close_waiting_screen(){
	$('#waitingLayer').css({
		height: 0,
		width: 0		
	});
}
function waiting_screen(){
	var height	=	$(document).height();
	var width	=	$(document).width();
        if(!$('#waitingLayer').attr('id')){
            $('body').append('<div id="waitingLayer"></div>');
        }
	$('#waitingLayer').css({
		height: height,
		'background-color': '#CCC',
		'z-index': '100',
		width: width,
		position: 'fixed',
		top: '0px',
		left: '0px'
	});
	if( $.browser.msie){
		$('#waitingLayer').css('filter', 'alpha(opacity = 50)');
	}else{
		$('#waitingLayer').css('opacity', '0.5');
	}
}


function order_filter_status(){
    document.adminForm.submit();
}

var h3l_timeout =  null;
function h3l_hide_alert(){
    $('#alert_layer').hide(1000, function(){
        clearTimeout(h3l_timeout);
        $(this).remove();
    });
}
function h3l_show_alert(input, text){
            clearTimeout(h3l_timeout);
            if($('#alert_layer').attr('id')){
                $('#alert_layer').remove();
            }
           
            $('body').append('<div id="alert_layer"></div>');
            $('#alert_layer').click(function(){
                h3l_hide_alert();
            });
            var position = $(input).position();
            $('#alert_layer').append('<p style="margin-left: 5px; margin-right: 5px;text-align: center; display: block;">' + text + '</p>');
            $('#alert_layer').css({
                'overflow': 'hidden',
                'height':'35px',
                'background-color': '#002D00',
                'left': position.left,
                'top': position.top - 35,
                'position': 'absolute',
                'color': '#CCC'
            });
            
            h3l_timeout   =   setTimeout(function(){
                h3l_hide_alert();
            }, 5000);
}

function saveTags(){
    var tags_selected   =   $('.list-tags [type="checkbox"]:checked');

    var tag_ids = new Array();
    $.each(tags_selected, function(index, el){
        tag_ids[index]   =   $(el).val();
    });
    var data    =   {
      'gameid': $('#savetags_gameid').val(),
      'tags_id': tag_ids.join('_')
    };
    $.ajax({
	url: RootbaseUrl + '/administrator/tags/savetags',
	dataType: 'html',
	context: document.body,
        data: data,
        type: 'post',
        success: function(data){
            if(data == '1'){
                $('.tags').fadeOut();
            }
        }
    });
}

function selectTags(gameid){
    $.ajax({
        cache: false,
	url: RootbaseUrl + '/administrator/tags/gettags/gameid:' + gameid,
	dataType: 'html',
	context: document.body,
        success: function(data){
            if(data != ''){
                $('.tags').fadeIn();
                $('.tags').html(data);
            }
        }
    });
}